package org.rency.crawler.common.exception;

import org.rency.crawler.common.enums.ReturnCode;

/**
 * 状态机异常
 *
 * @author: user_rcy@163.com <br>Created on 2016年7月19日
 * @version: V1.0.0
 * @since JDK 1.8
 */
public class MachineStateException extends RuntimeException {

  /**
   *
   */
  private static final long serialVersionUID = 4508892195634590017L;

  private ReturnCode returnCode;
  private String detailMessage;

  public MachineStateException() {
    super();
    this.returnCode = ReturnCode.MACHINE_STATE_FAILED;
  }

  public MachineStateException(Throwable t) {
    super(t);
    this.returnCode = ReturnCode.MACHINE_STATE_FAILED;
  }

  public MachineStateException(String detailMessage) {
    this(ReturnCode.MACHINE_STATE_FAILED,detailMessage);
  }

  public MachineStateException(ReturnCode returnCode, String detailMessage) {
    super(String.format("%s:%s[%s]", returnCode.getCode(), returnCode.getMsg(), detailMessage));
    this.returnCode = returnCode;
    this.detailMessage = detailMessage;
  }

  public ReturnCode getReturnCode() {
    return returnCode;
  }

  public void setReturnCode(ReturnCode returnCode) {
    this.returnCode = returnCode;
  }

  public String getDetailMessage() {
    return detailMessage;
  }

  public void setDetailMessage(String detailMessage) {
    this.detailMessage = detailMessage;
  }
}
